package work;

import java.util.Arrays;

/*
3 有一个数组,写一个法算,取数组中第一个数,然后把比它大的放在数组的右边,比它小的放在左边
 */
public class Work03 {
    public static void main(String[] args) {
        int [] array = {5, 1, 4, 1, 5, 9, 2, 6, 3, 7};
        arraySort(array);
        System.out.println(Arrays.toString(array));
    }
    static void arraySort(int[] array){
        int pivot = array[0];
        int left = 1;
        int right = array.length - 1;

        while (left <= right) {

            while (left <= right && array[left] < pivot) {
                left++;
            }

            while (left <= right && array[right] >= pivot) {
                right--;
            }

            if (left < right) {

                int temp = array[left];
                array[left] = array[right];
                array[right] = temp;
            }

        }

        int temp = array[0];
        array[0] = array[left - 1];
        array[left - 1] = temp;
    }
}
